package com.aliyun.messagemgt.web.controller;

import com.aliyun.messagemgt.application.service.BaseMessageSourceService;
import com.aliyun.messagemgt.common.errorcode.CommonErrorCode;
import com.aliyun.messagemgt.common.exceptions.BaseException;
import com.aliyun.messagemgt.dto.BaseMessageSourceDto;
import com.aliyun.messagemgt.dto.query.BaseMessageSourceQuery;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangshaobo
 * @date 2021年10月14日
 */
@Api(tags = "消息源相关接口")
@RestController
@Slf4j
public class BaseMsgSourceController {

    @Autowired
    private BaseMessageSourceService baseMessageSourceService;


    @PostMapping("/baseMsg/list")
    public Object listBaseMsgSource(@RequestBody BaseMessageSourceQuery baseMessageSourceQuery){
        return baseMessageSourceService.listBaseMsgSource(baseMessageSourceQuery);
    }


    @PostMapping("/baseMsg/isEnabled")
    public Object isEnabled(@RequestBody BaseMessageSourceDto baseMessageSourceDto){
        if (baseMessageSourceDto.getId() == null || baseMessageSourceDto.getIsEnabled() == null){
            throw new BaseException(CommonErrorCode.COMMON_PARAM_INVALID);
        }
        log.info("");
        return baseMessageSourceService.isEnabled(baseMessageSourceDto);
    }

    @PostMapping("/baseMsg/queryLog")
    public Object queryLog(@RequestBody BaseMessageSourceQuery messageSourceQuery){
        return baseMessageSourceService.queryLog(messageSourceQuery);
    }
}
